package com.corpgovernment.travelstandard.impl;

import com.corpgovernment.api.travelstandard.service.IMbTravelstandFlightCabinService;
import com.corpgovernment.api.travelstandard.vo.MbTravelstandFlightCabinVo;
import com.corpgovernment.common.base.AbstractBaseService;
import com.corpgovernment.common.utils.ListUtils;
import com.corpgovernment.common.utils.ObjectUtils;
import com.corpgovernment.travelstandard.entity.db.MbTravelstandFlightCabin;
import com.corpgovernment.travelstandard.mapper.MbTravelstandFlightCabinMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class MbTravelstandFlightCabinService extends AbstractBaseService implements IMbTravelstandFlightCabinService {

    @Autowired
    private MbTravelstandFlightCabinMapper mbTravelstandFlightCabinMapper;

    @Override
    public void insert(MbTravelstandFlightCabinVo model) {
        mbTravelstandFlightCabinMapper.insertSelective(ObjectUtils.copyProperties(model, MbTravelstandFlightCabin.class));
    }

    @Override
    public int delete(Long id) {
        return mbTravelstandFlightCabinMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int update(MbTravelstandFlightCabinVo model) {
        return mbTravelstandFlightCabinMapper.updateByPrimaryKeySelective(ObjectUtils.copyProperties(model,MbTravelstandFlightCabin.class));
    }

    @Override
    public MbTravelstandFlightCabinVo get(Long id) {
        return ObjectUtils.copyProperties(mbTravelstandFlightCabinMapper.selectByPrimaryKey(id),MbTravelstandFlightCabinVo.class);
    }

    @Override
    public List<MbTravelstandFlightCabinVo> list(MbTravelstandFlightCabinVo model) {
        return ListUtils.copyList(
                mbTravelstandFlightCabinMapper.list(ObjectUtils.copyProperties(model,MbTravelstandFlightCabin.class)),
                MbTravelstandFlightCabinVo.class
        );
    }

    @Override
    public int deleteByTsId(Long tsId, String tsType) {
        return mbTravelstandFlightCabinMapper.deleteByTsId(tsId, tsType);
    }

    @Override
    public void insertList(List<MbTravelstandFlightCabinVo> model) {
        List<MbTravelstandFlightCabin> flightCabinList = ListUtils.copyList(model,MbTravelstandFlightCabin.class);
        flightCabinList.forEach(t->{
            t.setDatachangeCreatetime(new Date());
            t.setDatachangeLasttime(new Date());
        });
        mbTravelstandFlightCabinMapper.insertList(flightCabinList);
    }

}
